#include<stdio.h>
#include<stdlib.h>
#include<unistd.h>
#include<string.h>
#include<sys/wait.h>
int main()
{
    int pipefd[2];
    __pid_t pid;
    char buf[100];
    const char*message="i am father";

    if(pipe(pipefd)==-1)
    {
        perror("pipe");
        exit(EXIT_FAILURE);
    }

    pid = fork();
    if(pid == -1)
    {
        perror("fork");
        exit(EXIT_FAILURE);
    }

    if(pid>0)
    {
        close(pipefd[0]);
        write(pipefd[1],message,strlen(message)+1);
        close(pipefd[1]);
        wait(NULL);
    }
    else
    {
        close(pipefd[1]);
        read (pipefd[0],buf,sizeof(buf));
        close(pipefd[0]);
        printf("Received from parent:%s\n",buf);
    }
    return 0;

}